package liveData.migration.toPhoenix.util.partitionUtils;

import liveData.migration.toPhoenix.entity.FlatMessage;
import liveData.migration.toPhoenix.util.StringUtils;
import org.apache.flink.api.java.functions.KeySelector;

import java.util.Map;

/**
 * @program: userPortrait
 * @description:
 * @author: sunteng
 * @create: 2020-08-21 13:38
 **/
public class UidKeySelecter implements KeySelector<FlatMessage, String> {

    private String mysqlPk;

    public UidKeySelecter(String mysqlPk) {
        this.mysqlPk = mysqlPk;
    }

    @Override
    public String getKey(FlatMessage value) {
        if (value == null || value.getIsDdl()) {
            return String.valueOf(Integer.MAX_VALUE);
        }

        Map<String, String> proMap = value.getData().get(0);
        if (proMap.containsKey(mysqlPk) && StringUtils.isNotEmpty(proMap.get(mysqlPk))) {
            return proMap.get(mysqlPk);
        }

        return String.valueOf(Integer.MAX_VALUE);
    }
}
